/**
 * 初始化信访登记页面通用的css style
 * 
 */
function initLfdjStyle(area) {
	var areaElement = (area == null ? document : area);

	var inputitems = areaElement.getElementsByTagName('input');

	for (var i = 0; i < inputitems.length; i++) {
		var item = inputitems[i];

		if (item.type == 'text' || item.type == 'file') {
			item.className = 'box1';
		} else if (item.type == 'hidden') {
			item.id = item.name;
		}
	}

	var areaitems = areaElement.getElementsByTagName('textarea');

	for (var i = 0; i < areaitems.length; i++) {
		var item = areaitems[i];

		item.className = 'bbox1';
	}
}

/* 来信登记人数 */
var delCountSize = 1;

function initCountItem() {
	var chks = document.getElementsByName('lxdtchk');

	if (chks.length > 0) {
		var str = '';
		for (var i = 0; i < chks.length; i++) {
			str += chks[i].getAttribute('idx') + ',';
		}

		createHidden('delCount', str);

		return true;
	} else {
		alert('请填写来信人详细信息');
		return false;
	}
}
/**
 * 增加来信人登记信息
 * 
 */
function addItem() {
	var count = 1;

	if (isNaN(count) || count <= 0) {
		alert('请输入正确的来信人数');
	} else {
		var idx = document.getElementById('lxr').rows.length - 1;

		var tr = document.getElementById('lxr').insertRow(document
				.getElementById('lxr').rows.length);

		tr.id = 'lxdt_' + idx;

		var td0 = tr.insertCell(tr.cells.length);
		td0.style.border = '0px';
		td0.innerHTML = '<input type="checkbox" name="lxdtchk" value="lxdt_'
				+ idx + '" idx="' + idx + '"/>';

		var td1 = tr.insertCell(tr.cells.length);
		td1.style.border = '0px';
		td1.innerHTML = '<input type="hidden" name="lxdtid_' + idx
				+ '" id="lxdtid_' + idx
				+ '" /><input type="text" class="box1" name="XF_USERNAME_'
				+ idx + '" id="XF_USERNAME_' + idx + '" />';
		var td2 = tr.insertCell(tr.cells.length);
		td2.style.border = '0px';
		td2.innerHTML = '<select name="XF_USERSEX_'
				+ idx
				+ '" id="XF_USERSEX_'
				+ idx
				+ '"><option value="1">男</option><option value="0">女</option></select>';
		var td3 = tr.insertCell(tr.cells.length);
		td3.style.border = '0px';
		td3.innerHTML = '<input type="text" name="XF_USERAGE_' + idx
				+ '" id="XF_USERAGE_' + idx + '" />';
		var td4 = tr.insertCell(tr.cells.length);
		td4.style.border = '0px';
		/*td4.innerHTML = '<input type="text" name="XF_USERLICENSE_' + idx
				+ '" id="XF_USERLICENSE_' + idx + '" onblur="checktheform(this)"/>';*/
		td4.innerHTML = '<input type="text" name="XF_USERLICENSE_' + idx
				+ '" id="XF_USERLICENSE_' + idx + '" />';
		var td5 = tr.insertCell(tr.cells.length);
		td5.style.border = '0px';
		td5.innerHTML = '<input type="text" name="XF_USERTEL_' + idx
				+ '" id="XF_USERTEL' + idx + '" />';
		var td6 = tr.insertCell(tr.cells.length);
		td6.style.border = '0px';
		/*td6.innerHTML = '<input type="text" name="XF_USERCODE_' + idx
				+ '" id="XF_USERCODE_' + idx + '" onblur="isPostalCode(this)"/>';*/
		td6.innerHTML = '<input type="text" name="XF_USERCODE_' + idx
		+ '" id="XF_USERCODE_' + idx + '" />';
		var td7 = tr.insertCell(tr.cells.length);
		td7.style.border = '0px';
		td7.innerHTML = '<input type="text" name="XF_USERADDRESS_' + idx
				+ '" id="XF_USERADDRESS_' + idx + '" />';

		initLfdjStyle(document.getElementById('lxr'));
	}
}

/**
 * 删除来信人登记信息
 */
function removeItem() {
	var chks = document.getElementsByName('lxdtchk');

	var chksItems = [];

	for (var i = 0; i < chks.length; i++) {
		if (chks[i].checked) {
			chksItems.push(chks[i].value);
		}
	}

	if (chksItems.length == 0) {
		alert('请选择要删除的信访人登记信息');
	} else {
		
		for (var i = 0; i < chksItems.length; i++) {
			if ($('lfdtid_' + i)) {
				/* 删除多数据项实际数据 */
				removeItemFromDB($('lfdtid_' + i).value, 'APP_LFDTL');
			}
			//alert("$(chksItems[i]).parentNode====="+$(chksItems[i]).parentNode);
			$(chksItems[i]).parentNode.removeChild($(chksItems[i]));
		}
	}
}

function lianxinxiBlock() {
	document.getElementById('lianxinxi').style.display = "block";

}

function lianxinxiNone() {
	document.getElementById('lianxinxi').style.display = "none";

}

function richangjiedai(flag) {
	if (flag == true) {// true
		document.getElementById('jdr1').style.display = "block";
		document.getElementById('jdr2').style.display = "block";
		lingdao1.style.display = "none";
		lingdao1.style.display = "none";
		
		var jdr = document.getElementById('jdr');
		jdr.setAttribute("colneed", "1");
		
		
		document.getElementById('JDLDNAME').value= "";
		document.getElementById('JDLDID').value= "";
		document.getElementById('LDZWNAME').value= "";
		document.getElementById('LDZWID').value= "";
		var JDLDNAME = document.getElementById('JDLDNAME');
		JDLDNAME.setAttribute("colneed", "0");
		Ext.getCmp('LDZWID_').clearValue();
	} else if (flag == false) {
		document.getElementById('jdr1').style.display = "none";
		document.getElementById('jdr2').style.display = "none";
		document.getElementById('lingdao1').style.display = "block";
		document.getElementById('lingdao1').style.display = "block";
		var jdr = document.getElementById('jdr');
		jdr.setAttribute("colneed", "0");
		
		document.getElementById('jdr').value = "";
		
		var JDLDNAME = document.getElementById('JDLDNAME');
		JDLDNAME.setAttribute("colneed", "1");
	}
}

/**
 * 根据人数判断是个人还是集体访(人数>=6)
 */
function setJFT(conut) {
	if (conut >= 6) {
		document.getElementById('JTF').value = 1;
	} else {
		document.getElementById('JTF').value = 0;
	}

}